package mini_v340

import io.gatling.core.Predef._
import io.gatling.core.structure.ChainBuilder
import io.gatling.http.Predef._
import conf._
/**
  * Created by chenbo on 2018/9/6.
  */
object Users {

  def token:ChainBuilder ={

    val data = Map(
      "grant_type" -> "wx_miniprogram",
      "code" -> "benlaiTest|${unionId}",
      "encryptedData" -> "111",
      "iv" -> "111",
      "systemInfo" -> "{\"model\":\"iPhone 6\",\"pixelRatio\":2,\"windowWidth\":375,\"windowHeight\":555,\"system\":\"iOS 10.0.1\",\"language\":\"zh_CN\",\"version\":\"6.6.3\",\"batteryLevel\":98,\"screenWidth\":375,\"screenHeight\":667,\"SDKVersion\":\"1.9.91\",\"brand\":\"devtools\",\"fontSizeSetting\":16,\"statusBarHeight\":20,\"platform\":\"devtools\"}"
    )

    exec(_.set("token","Basic YmVubGFpX21pbmlwcm9ncmFtOjdhOTRmMTkwNjA5MzExZTdhNmYxNWZiMDlmNWY4Y2Yw"))
    .exec(
      Request.post(Config.Token,data)
        .check( jsonPath("$.msg").is("success"))
        .check( jsonPath("$..access_token").saveAs("access_token") )
    ).exec(session => session.set("token","bearer "+session("access_token").as[String]))
  }

  def user_me:ChainBuilder={

    exec(
      Request.get(Config.Me)
        .check( jsonPath("$..msg").is("success"))
    )
  }

  def home:ChainBuilder ={

    val A:Map[String,Any] =Map("areaSysNo"->Apply.apply.area)
    exec(
      Request.get(Config.Home,A)
        .check( jsonPath("$..msg").is("success"))
    )
  }
}
